<?php
class mata_pelajaran extends MY_Controller{
    function mata_pelajaran(){
        parent::MY_Controller();
        $this->data['title'] = "Master Data Mata Pelajaran";
        $this->load->model('m_kelas');
        $this->load->model('m_mata_pelajaran');
    }
    
    var $data;
    var $limit = 10;
    function index(){
        $this->get_mata_pelajaran();
    }
    function get_mata_pelajaran($offset = 0){
        $this->data['content'] = "mata_pelajaran/v_mata_pelajaran";
        
        $uri_segment = 3;
        if($offset != 0){
          $offset = $this->uri->segment($uri_segment);  
        }
        $num_rows = $this->m_mata_pelajaran->getCountRows();
        $this->data['listMataPelajaran'] = $this->m_mata_pelajaran->getListMataPelajaran($offset,$this->limit);
        $config['base_url'] = site_url('mata_pelajaran/get_mata_pelajaran');
        $config['total_rows'] = $num_rows;
        $config['per_page'] = $this->limit;
        $config['uri_segment'] = $uri_segment;
        $this->pagination->initialize($config);
        $this->data['pagination'] = $this->pagination->create_links();
        $this->data['offset'] = $offset;
        
        $this->render($this->data);
    }
    function add_mata_pelajaran_form($offset = 0){
        $this->data['content'] = "mata_pelajaran/v_mata_pelajaran";
        $this->data['subLink'] = "mata_pelajaran/add_mata_pelajaran_proses";
        $this->data['formTitle'] = "Form Tambah Data Mata Pelajaran";
        $this->data['formView'] = "mata_pelajaran/addMataPelajaranForm";
        
        $uri_segment = 3;
        if($offset != 0){
          $offset = $this->uri->segment($uri_segment);  
        }
        $num_rows = $this->m_mata_pelajaran->getCountRows();
        $this->data['listMataPelajaran'] = $this->m_mata_pelajaran->getListMataPelajaran($offset,$this->limit);
        $this->data['listKelas'] = $this->m_kelas->getListKelas();
        $config['base_url'] = site_url('mata_pelajaran/add_mata_pelajaran_form');
        $config['total_rows'] = $num_rows;
        $config['per_page'] = $this->limit;
        $config['uri_segment'] = $uri_segment;
        $this->pagination->initialize($config);
        $this->data['pagination'] = $this->pagination->create_links();
        $this->data['offset'] = $offset;
        
        $this->render($this->data);
    }
    function edit_mata_pelajaran_form($id,$offset = 0){
        $this->data['content'] = "mata_pelajaran/v_mata_pelajaran";
        $this->data['subLink'] = "mata_pelajaran/edit_mata_pelajaran_proses";
        $this->data['formTitle'] = "Form Edit Data Mata Pelajaran";
        $this->data['formView'] = "mata_pelajaran/editMataPelajaranForm";
        $this->data['dataInput'] = $this->m_mata_pelajaran->getMataPelajaranById($id);
        
        $uri_segment = 4;
        if($offset != 0){
          $offset = $this->uri->segment($uri_segment);  
        }
        $num_rows = $this->m_mata_pelajaran->getCountRows();
        $this->data['listMataPelajaran'] = $this->m_mata_pelajaran->getListMataPelajaran($offset,$this->limit);
        $this->data['listKelas'] = $this->m_kelas->getListKelas();
        $config['base_url'] = site_url('mata_pelajaran/edit_mata_pelajaran_form/'.$id);
        $config['total_rows'] = $num_rows;
        $config['per_page'] = $this->limit;
        $config['uri_segment'] = $uri_segment;
        $this->pagination->initialize($config);
        $this->data['pagination'] = $this->pagination->create_links();
        $this->data['offset'] = $offset;
        
        $this->render($this->data);
    }
    function add_mata_pelajaran_proses(){
        $data = array('nama' => $this->input->post('nama'),
            'id_kelas' => $this->input->post('kelas'));
        $insert = $this->m_mata_pelajaran->addMataPelajaran($data);
        if($insert == TRUE){
            $this->session->set_flashdata("message",1);
        }else{
            $this->session->set_flashdata("message",2);
        }
        
        redirect("mata_pelajaran");
    }
    function edit_mata_pelajaran_proses(){
        $data = array('id' => $this->input->post('id'),
            'nama' => $this->input->post('nama'),
            'id_kelas' => $this->input->post('kelas'));
        $update = $this->m_mata_pelajaran->editMataPelajaran($data);
        if($update == TRUE){
            $this->session->set_flashdata("message",1);
        }else{
            $this->session->set_flashdata("message",2);
        }
        
        redirect("mata_pelajaran");
    }
    function delete_mata_pelajaran($id){
        $delete = $this->m_mata_pelajaran->deleteMataPelajaran($id);
        if($delete == TRUE){
            $this->session->set_flashdata("message",3);
        }else{
            $this->session->set_flashdata("message",4);
        }
        
        redirect("mata_pelajaran");
    }
}
?>
